﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="EditCustomer.aspx.cs" Inherits="Customer_EditCustomer" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <h1>
        Edit Customer Details
    </h1>
    <div class="HolderDiv">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
            DataKeyNames="license_no" DataSourceID="SqlDataSource1" EnableModelValidation="True"
            Font-Size="Small" ForeColor="Black" GridLines="Vertical" 
            AllowPaging="True" AllowSorting="True"
            EditRowStyle-CssClass="HolderDiv" BackColor="White" BorderColor="#DEDFDE" 
            BorderStyle="None" BorderWidth="1px" PageSize="5">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowEditButton="True" ButtonType="Button" />
                <asp:BoundField DataField="license_no" HeaderText="License Number" ReadOnly="true"
                    SortExpression="license_no" />
                <asp:BoundField DataField="first_name" HeaderText="First Name" SortExpression="first_name" />
                <asp:BoundField DataField="last_name" HeaderText="Last Name" SortExpression="last_name" />
                <asp:BoundField DataField="house_no" HeaderText="House Number" SortExpression="house_no" />
                <asp:BoundField DataField="street" HeaderText="Street" SortExpression="street" />
                <asp:BoundField DataField="apartment_no" HeaderText="Apartment Number" SortExpression="apartment_no" />
                <asp:BoundField DataField="city" HeaderText="City" SortExpression="city" />
                <asp:BoundField DataField="state" HeaderText="State" SortExpression="state" />
                <asp:BoundField DataField="zip_code" HeaderText="Zip Code" SortExpression="zip_code" />
                <asp:TemplateField HeaderText="Phone Number" SortExpression="phone_no">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("phone_no") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("phone_no") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Birth Date" SortExpression="birth_date">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("birth_date", "{0:yyyy/MM/dd}") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("birth_date", "{0:yyyy/MM/dd}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
            </Columns>
            <EditRowStyle BorderColor="Black" HorizontalAlign="Center" VerticalAlign="Middle"
                Width="400px" />
            <FooterStyle BackColor="#CCCC99" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        </asp:GridView>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MySqlConnectionString %>"
        DeleteCommand="DELETE FROM customers WHERE license_no=@license_no;" ProviderName="<%$ ConnectionStrings:MySqlConnectionString.ProviderName %>"
        SelectCommand="select * from customers;" UpdateCommand="UPDATE customers SET first_name =@first_name, last_name =@last_name, house_no =@house_no, street =@street, apartment_no =@apartment_no, city =@city, state =@state, zip_code =@zip_code, birth_date =@birth_date, phone_no =@phone_no where license_no=@license_no LIMIT 1;">
        <DeleteParameters>
            <asp:QueryStringParameter Name="license_no" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:QueryStringParameter Name="license_no" Type="String" />
            <asp:QueryStringParameter Name="first_name" Type="String" />
            <asp:QueryStringParameter Name="last_name" Type="String" />
            <asp:QueryStringParameter Name="house_no" Type="String" />
            <asp:QueryStringParameter Name="street" Type="String" />
            <asp:QueryStringParameter Name="apartment_no" Type="String" />
            <asp:QueryStringParameter Name="city" Type="String" />
            <asp:QueryStringParameter Name="state" Type="String" />
            <asp:QueryStringParameter Name="zip_code" Type="String" />
            <asp:QueryStringParameter Name="phone_no" Type="String" />
            <asp:QueryStringParameter Name="birth_date" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>
